package com.say.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.say.bean.domain.User;

import java.util.List;

@Repository
public interface UserDao extends JpaRepository<User, String> {

	public Page<User> findAll(Specification<User> specification, Pageable page);
	
	public User getUserByOpenId(String openId);
	
	@Query(nativeQuery = true, value = "update user set mood = ?2   where id = ?1 ")
	@Modifying
    public void updateMoodById(String userId, String mood);
	 
	@Query(nativeQuery = true, value = "update user set open_id = ?2   where id = ?1 ")
	@Modifying
	public void updateOpenId(String id, String openId);

	@Query(nativeQuery = true, value = "select open_id from user  where id =?1  ")
	public String getOpenId(String id);
	
	@Query(nativeQuery = true, value = "select id from user  where open_id =?1  ")
	public String findUserById(String openId);
	
	@Query(nativeQuery = true, value = "select * from user  where user_name =?1  ")
	public User getUserByUserName(String userName);

	public List<User> findByIdIn(List<String> ids);
	
	public User findByMobile(String mobile);
	
	@Query(nativeQuery = true, value = "SELECT u.* from `user` u LEFT JOIN friends t ON t.to_user_id=u.id WHERE t.user_id=?1 GROUP BY u.id ORDER BY u.id ASC ")
	public List<User> findFriendsByUserId(String userId);
	
	

}
